'use strict';
const ossParam = require("../util/ossUtil/aliyun.js")
const OSS = require("ali-oss");
const ossClient = new OSS({
	region: ossParam.region,
	accessKeyId: ossParam.accessid,
	accessKeySecret: ossParam.accesskey,
	bucket: ossParam.bucket
});

module.exports = {
	/**
	 * 删除指定存储文件
	 * @url admin/upload/pub/delete 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		let { image } = data;
		if(Array.isArray(image)) {
			image = image.map(item => {
				const img = item.slice(ossParam.host.length + 1)
				return img
			})
			const result = await ossClient.deleteMulti(image)
		} else {
			image = image.slice(ossParam.host.length + 1)
			
			const result = await ossClient.delete(image);
		}
		res["msg"] = "操作成功！"
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
